#set(modelClass = cls.getModuleClass("model"))
#set(modelProxyClass = cls.getModuleProxyClass("model"))
#set(modelVar = cls.getModuleVar("model"))
package #(parentPackage);

import com.easy.query.api.proxy.client.EasyEntityQuery;
import com.easy.query.solon.annotation.Db;
import #(cls.getModulePackage("model"));
import #(cls.getModuleProxyPackage("model"));
import com.goldsyear.solon.common.core.exception.ErrorCode;
import com.goldsyear.solon.common.core.exception.ServiceException;
import com.goldsyear.solon.common.core.model.PlainOption;
import com.goldsyear.solon.web.model.PageResult;
import com.goldsyear.solon.web.model.query.QPage;
import #(cls.superClass);
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;


/**
 * #(cls.comment) Service 服务层
 *
 * @author #(author)
 * @since #(since)
 */
@Component
@Slf4j
public class #(cls.moduleClass) extends #(cls.superClassSimple)<#(modelClass), #(modelProxyClass)> {
  @Db private EasyEntityQuery easyEntityQuery;

  public #(cls.moduleClass)() {
    super(#(modelClass).class, #(modelProxyClass).class);
  }

  public Boolean create#(modelClass)(#(modelClass) #(modelVar)) {
    return save(#(modelVar));
  }

  public Boolean update#(modelClass)(#(modelClass) #(modelVar)) {
    return updateById(#(modelVar));
  }

  public #(modelClass) get#(modelClass)(#(cls.pkClass) #(cls.pk)) {
    return getById(#(cls.pk));
  }

  public Boolean delete#(modelClass)(#(cls.pkClass) #(cls.pk)) {
    if (getById(id) == null) {
      throw new ServiceException(ErrorCode.builder().msg("记录不存在").build());
    }

    return deleteById(#(cls.pk));
  }

  public Boolean batchDel#(modelClass)(List<#(cls.pkClass)> #(cls.pk)s) {
    for (#(cls.pkClass) id : ids) {
      if (getById(id) == null) {
        throw new ServiceException(ErrorCode.builder().msg("记录不存在").build());
      }
    }

    return deleteByIds(#(cls.pk)s);
  }

  public List<#(modelClass)> list#(modelClass)(#(modelClass) #(modelVar)) {
    return list(#(modelVar));
  }

  public List<#(modelClass)> simpleList#(modelClass)(#(modelClass) #(modelVar)) {
    return list(#(modelVar));
  }


  public PageResult<#(modelClass)> paginate#(modelClass)(QPage qPage, #(modelClass) #(modelVar)) {
    return paginate(qPage, #(modelVar));
  }

  public List<PlainOption> options#(modelClass)(#(modelClass) #(modelVar)) {
    return listAs(#(modelVar), PlainOption.class);
  }

  @Override
  protected EasyEntityQuery easyEntityQuery() {
    return easyEntityQuery;
  }
}